// pages/schedule/addschedule/addschedule.js
const app = getApp()
import validate from '../../../utils/validate.js'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    schedules:'',
    gids:'',
    num:-1,
    storename:'',
    storeid:'',
    userid:'',
    myOffLineList:[]

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      gids:options.gids,
      schedules:options.schedules,
      storeid:options.storeid,
      storename:options.storename,
      num:options.num,
    })
    this.search()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  search:function(){
    let that = this;
    app.api.getMyPromlist(this.data.storeid).then(res => {
      if(res.code == 200){
        that.setData({
          myOffLineList : res.rows
        })
      }
    })
  },
  submit:function(){
    if( validate.validatenull(this.data.userid)){
      app.dialog.waring('请选择促销人员');
      return;
    }
    let data = {gid:this.data.gids,storeid:this.data.storeid,userid:this.data.userid}
    app.api.addSchedule(data).then(res =>{
      wx.showModal({
        title: '提示',
        content: '保存成功!',
        showCancel:false,
        success(res) {
          wx.navigateBack()
        }
      })
    })
  },
  selectedCheck:function(e){
    let list = e.detail.value;
    console.log(list);
    let users = ''
    for(let it of list){
      if(users.length > 0){
        users += "," ;
      }
      users += this.data.myOffLineList[it].userid ;
    }
    this.setData({
      'userid' :users
    })
  },
})